import { defineStore } from "pinia";

// KeepAliveStore
export const useKeepAliveStore = defineStore({
    id: "KeepAliveStore",
    state: () => ({
        keepAliveName: [] as string[]
    }),
    actions: {
        // addKeepAliveName
        async addKeepAliveName(name: string) {
            !this.keepAliveName.includes(name) && this.keepAliveName.push(name);
        },
        // removeKeepAliveName
        async removeKeepAliveName(name: string) {
            this.keepAliveName = this.keepAliveName.filter(item => item !== name);
        },
        // setKeepAliveName
        async setKeepAliveName(keepAliveName: string[] = []) {
            this.keepAliveName = keepAliveName;
        }
    }
});

/** 缓存组件 示例：*/
// <router-view v-slot="{ Component, route }">
//     <transition appear name="fade-transform" mode="out-in">
//         <keep-alive :include="usekeepAliveStore.keepAliveName">
//             <component :is="Component" :key="route.path" v-if="isRouterShow" />
//         </keep-alive>
//     </transition>
// </router-view>
